﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using InkFx.WinControl.Core;

namespace InkFx.WinControl
{
    public class NoneForm : System.Windows.Forms.Form
    {
        public NoneForm()
        {
            base.SetStyle(ControlStyles.Selectable, false);

            //base.DoubleBuffered = true; //这种需要快速弹出的窗体, 设置 双缓冲 只会减慢启动速度
            base.ShowInTaskbar = false;
            base.FormBorderStyle = FormBorderStyle.None;
            base.TransparencyKey = Win32API.Transparent;
            base.StartPosition = FormStartPosition.Manual;
        }

        protected Rectangle m_InitBounds = Rectangle.Empty;

        /// <summary>
        /// 以非激活模式 显示窗体
        /// </summary>
        public virtual new void Show(IWin32Window owner)
        {
            this.Show(owner, Rectangle.Empty);
        }
        /// <summary>
        /// 以非激活模式 显示窗体
        /// </summary>
        public virtual new void Show(IWin32Window owner, Rectangle bounds)
        {
            base.Owner = owner as System.Windows.Forms.Form;
            base.Bounds = new Rectangle(-100, -100, 2, 2);
            Win32API.ShowWindow(this.Handle, 4);
            base.OnLoad(EventArgs.Empty);
            base.OnShown(EventArgs.Empty);
        }
        
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            base.DoubleBuffered = true;  //在正式显示后 再开启双缓冲
            if (m_InitBounds.Width >= 1 && m_InitBounds.Height >= 1) base.Bounds = m_InitBounds;
        }
    }
}
